package com.scsj.supermarket.view.activity.mainmodel;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.alibaba.fastjson.JSONObject;
import com.orhanobut.logger.Logger;
import com.scsj.supermarket.R;
import com.scsj.supermarket.adapter.ShopListBaseAdapter;
import com.scsj.supermarket.base.IndexFuncBase;
import com.scsj.supermarket.bean.IndexTenFuncBean;
import com.scsj.supermarket.bean.ShopListBaseBean;
import com.scsj.supermarket.presenter.IndexFuncPresenter;
import com.scsj.supermarket.view.activity.baseactivitymodel.BaseActivity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import es.dmoral.toasty.Toasty;
import okhttp3.MediaType;
import okhttp3.RequestBody;

public class RobActivity extends BaseActivity implements IndexFuncBase.IView {

    private RecyclerView rob_rv;
    private IndexFuncPresenter presenter;
    private ShopListBaseAdapter adapter;
    private ArrayList<ShopListBaseBean.ShopListBase> data;

    @Override
    protected void createView(Bundle savedInstanceState) {
        setContentView(R.layout.activity_rob);

        initToolbar();
        setToolbarTitle("限时抢购");
        hasBack(true);

        presenter = new IndexFuncPresenter(this);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("cityName", "郑州市");
        jsonObject.put("advertisingSpaceTemplate", "link_target_advertising_space");
        jsonObject.put("urlTargetExplain", "app_sczs");
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json;charset=utf-8"), jsonObject.toString());
        presenter.deliverAllList(requestBody);

        initView();
    }

    @Override
    protected void initView() {
        rob_rv = findViewById(R.id.rob_rv);
        rob_rv.setLayoutManager(new LinearLayoutManager(this));
        rob_rv.setNestedScrollingEnabled(false);
      data =new ArrayList<>();
    }

    @Override
    protected void initListener() {

    }

    @Override
    protected void initData() {

    }


    @Override
    public void showSuccessMsg(String s) {
        Toasty.success(mContext, s).show();
    }

    @Override
    public void showErrorMsg(String s) {
        Toasty.success(mContext, s).show();
    }

    @Override
    public void setAllData(IndexTenFuncBean indexTenFuncBean) {
        for (int i = 0; i < indexTenFuncBean.getData().get(3).getAppAdvertisingVoList().size(); i++) {
            Toasty.error(mContext,indexTenFuncBean.getData().get(3).getAppAdvertisingVoList().size()+"pppppp").show();
            HashMap map = new HashMap();
            map.put(0, "这是图片URL");
            map.put(1, "CBD商圈");
            map.put(2, "黑人牙膏，亮白银子 182/支");
            map.put(3, "美白两边，注重生活");
            map.put(4, "销量10");
            map.put(5, "收藏20");
            map.put(6, "¥26.52");
            map.put(7, "¥12.36");

            data.add(new ShopListBaseBean.ShopListBase(map));
        }
        adapter = new ShopListBaseAdapter(data);
        rob_rv.setAdapter(adapter);
    }
}
